package com.lzs.Service.Impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lzs.DAO.MemberDAO;
import com.lzs.PO.Family;
import com.lzs.PO.Member;
import com.lzs.PO.Page;
import com.lzs.Service.MemberService;

@Service
public class MemberServiceImpl implements MemberService{

	@Autowired
	private MemberDAO memberDAO;
	
	public Boolean countMemberByPeopleId(String people_id) {
		
		long count = this.memberDAO.countMemberByPeopleId(people_id);
		return count==0;
	}

	
	public void addMember(Map<String, Object> map) {
		
		this.memberDAO.addMember(map);
		
	}


	
	public Member findMemberByFamilyId(String family_id) {
		
		Member member = this.memberDAO.findMemberByFamilyId(family_id);
		
		return member;
	}


	
	public void updateMember(Map<String, Object> map) {
		
		this.memberDAO.updateMember(map);
		
	}


	
	public void deleteMember(String family_id) {
		
		this.memberDAO.deleteMember(family_id);
		
	}


	@Override
	public Page<Member> findMemberPagelist(String keyword, Integer pageSize, Integer pageNum) {
		
		List<Member> arealist = this.memberDAO.findMemberList(keyword);

		int totalRecord = arealist.size();

		Page<Member> page = new Page<Member>(pageNum, pageSize, totalRecord);

		int startIndex = page.getStartIndex();

		page.setList(memberDAO.findMemberPagelist(keyword, startIndex, pageSize));
		
		return page;
	}


	
	public Member findMemberWithFamily(String family_id) {
		
		Member member = this.memberDAO.findMemberWithFamily(family_id);
		
		return member;
	}


	
	public void deleteMemberByPeopleId(String people_id) {
	    
		  this.memberDAO.deleteMemberByPeopleId(people_id);
		
	}



	public List<Member> findMembersByFamilyId(String family_id) {
		
		List<Member> memberlist = this.memberDAO.findMembersByFamilyId(family_id);
		
		return memberlist;
	}


	@Override
	public Member findMemberByPeopleId(String people_id) {
		
		Member member = this.memberDAO.findMemberByPeopleId(people_id);
		
		return member;
	}

}
